﻿using AuthCenter.Data.Database;
using ExcelConfig;
using ExcelConfig.Config;
using System;

namespace AuthCenter.Import
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            switch (args[0].ToLower())
            {
                case "user":
                    var userfile = args[1];
                    var db_auth = new AuthDB();
                    foreach (var user in ExcelRead2.Query(userfile, "用户导入"))
                    {
                        Console.Write($"import {user.Text("账号")} ");
                        var userId = db_auth.MakeUser(user.Text("账号"), user.Text("密码"), user.Text("加密方式"));
                        db_auth.UpdateUserInfo(new Data.Model._202411.UserInfo
                        {
                            UserID = userId,
                            Name = user.Text("姓名"),
                            Roles = user.Text("角色"),
                            Gender = user.Text("性别"),
                            Address = user.Text("地址"),
                            Phone = user.Text("手机"),
                            Tel = user.Text("座机号"),
                            Email = user.Text("邮箱"),
                            Remark = user.Text("备注"),
                        });
                        foreach (var link_app in (user.Text("绑定应用")).Split(","))
                        {
                            db_auth.LinkApp(userId, link_app);
                        }
                        Console.WriteLine($"ok");
                    }
                    break;
                case "app":
                    var appfile = args[1];
                    var db_auth_app = new AuthDB();
                    foreach (var app in ExcelRead2.Query(appfile, "应用导入"))
                    {
                        db_auth_app.MakeApp(app.Text("代码"), app.Text("名称"), app.Text("加密方式"), app.Text("授权前缀"));
                    }
                    break;
            }
        }
    }
}
